<?php
/**
 * Created by PhpStorm
 * USER:  Zhaoys
 * Date:  2024/3/11
 */

namespace App\Providers;

use League\Container\ServiceProvider\AbstractServiceProvider;

class ViewServiceProvider extends AbstractServiceProvider
{
    protected $viewPath;
    protected $cachePath;
    protected $provides = [
        'twig'
    ];

    public function __construct()
    {
        $this->viewPath = __DIR__ . '/../../resources/views';
        $this->cachePath = __DIR__ . '/../../storage/views';
    }

    public function provides(string $id): bool
    {
        // TODO: Implement provides() method.
        return isset($this->provides[$id]) ? true : false;
    }

    public function register(): void
    {
        $container = $this->getContainer();
        $container->add('twig', function () {
            $loader = new \Twig\Loader\FilesystemLoader($this->viewPath);

            $twig = new \Twig\Environment($loader, [
                'cache' => false,
            ]);
            return $twig;
        });
    }
}
